#include "UserCaption.h"
#include "window-basic-main.hpp"
#include <QHBoxLayout>


UserCaption::UserCaption(QWidget *parent):QWidget(parent)
{
	setAttribute(Qt::WA_StyledBackground, true);
	init();
	bind();
}


UserCaption::~UserCaption()
{

}

void UserCaption::setIcon(const QPixmap& pixmap)
{
	userIcon->setVisible(true);
	userIcon->setPixmap(pixmap);
	userIcon->setScaledContents(true);
}

void UserCaption::setTitle(const QString& text)
{
	userTitle->setText(text);
}

void UserCaption::setHeight(int h) 
{
	if (h < 30) {
		return;
	}
	height = h;
	setFixedHeight(h);
	userIcon->setFixedSize(QSize(h-2, h-2));
}

void UserCaption::init()
{
	userIcon = new QLabel(this);
	userIcon->setVisible(false);
	userTitle = new QLabel(this);
	userClose = new QPushButton(this);
	QHBoxLayout* layout = new QHBoxLayout;
	layout->addWidget(userIcon);
	layout->addWidget(userTitle);
	layout->addStretch();
	layout->addWidget(userClose);
	layout->setMargin(0);
	setLayout(layout);
}

void UserCaption::bind()
{
	connect(userClose, &QPushButton::clicked,
		[this]() {
		emit closeSignal();
	});
}